package com.buka.blog.controller;

import com.buka.blog.entity.Blog;
import com.buka.blog.service.BlogService;
import com.buka.common.ResultJson;
import com.buka.menu.entity.Menu;
import com.buka.menu.service.MenuService;
import com.buka.user.entity.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

@WebServlet("/blog/list")
public class ListServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        //登录成功之后。用户信息存到了session

        HttpSession session = req.getSession();
        User loginUser = (User) session.getAttribute("loginUser");
        Long id = loginUser.getId();

        //根据用户id 获取当前用户的角色，查询菜单列表
        MenuService menuService = new MenuService();
        List<Menu> menus = menuService.listByUserId(id);
        req.setAttribute("menuList",menus);

        String pageNumStr = req.getParameter("pageNum");
        String pageSizeStr = req.getParameter("pageSize");
        if(null == pageNumStr){
            pageNumStr = "1";
        }
        if(null == pageSizeStr){
            pageSizeStr = "5";
        }

        int pageNum = Integer.parseInt(pageNumStr);
        int pageSize = Integer.parseInt(pageSizeStr);



        //博文列表
//        BlogService blogService = new BlogService();
//        List<Blog> list = blogService.list(pageNum,pageSize);
//        req.setAttribute("blogList", list);
        req.getRequestDispatcher("/index.jsp").forward(req, resp);




//        resp.getWriter().write(ResultJson.success(list));


    }
}
